package com.mcmaster.android.menus;

import java.io.FileNotFoundException;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.mcmaster.android.Output;
import com.mcmaster.android.R;
import com.mcmaster.android.R.layout;
import com.mcmaster.android.control.GuidedTourControl;
import com.mcmaster.android.data.*;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class GuidedMenu extends MapActivity {
	
	String contents_;
	Building current_building_;
	MapController mapctrl_;
	GuidedTourControl controller_;
	
	public void onCreate(Bundle savedInstanceState) {
		Bundle extras = getIntent().getExtras();
		String tour_name_ = extras.getString("name");
		
		super.onCreate(savedInstanceState);
		setContentView(layout.guided_layout_1);
		
		MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
        
		Button guided_scan_btn = (Button)findViewById(R.id.guided_scan_btn);
		Button guided_tours_btn = (Button)findViewById(R.id.guided_tours_btn);
		
		guided_scan_btn.setOnClickListener(new ButtonHandlerScan());
		guided_tours_btn.setOnClickListener(new ButtonHandlerTourMenu());
		
		try {
			controller_ = new GuidedTourControl(this, mapView, TourDatabase.getTourFromName(tour_name_));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	private class ButtonHandlerTourMenu implements View.OnClickListener {
	    public void onClick(View v) {
	    	handleTourClick();
	    }
	}
	
	private void handleTourClick() {
		finish();
	}
	
	private class ButtonHandlerScan implements View.OnClickListener {
	    public void onClick(View v) {
				try {
					handleScanClick();
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
	    }
	}
	
	private void handleScanClick() throws FileNotFoundException {	
		controller_.startQRReader();
	}
	
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}